<template>
<div class="main">
  <div class="heard">
    <div class="nav"><a></a>
    </div>
    <h2 class="pag_title">新建收货地址</h2>
  </div>
  <van-address-edit
  :area-list="areaList"
  show-postal
  show-delete
  show-set-default
  show-search-result
  :search-result="searchResult"
  :area-columns-placeholder="['请选择', '请选择', '请选择']"
  @save="onSave(addressInfo)"
  @delete="onDelete"
  @change-detail="onChangeDetail"
  :address-info="addressInfo"
/>

</div>
 
</template>

<script>
console.log(base_url)

import {base_url} from '../utils/baseURL'
  import { Toast } from 'vant';
   import { areaList } from '@vant/area-data';
import axios from "axios"
export default {
  data() {
    return {
      areaList,
      searchResult: [],
      addressInfo:{
                name:'张三丰',
                tel:'13933335555',
                province:'',
                city:'',
                county:'',
                addressDetail:'大西洋国际',
                areaCode:'110102',
                postalCode:'400000',
                isDefault:true,
                address:'',
            }
    };
  },
  methods: {
    onSave(content) {
      let item = sessionStorage.getItem("userinfo")
      let userId=JSON.parse(item)._id
      let newAddress = {
        userId,
        ...content
      }
      console.log(newAddress);//地址中省份信息添加不进去？？
      this.$store.dispatch('address/addressAddAct',newAddress)
      this.$router.push('/checkouts')
    },
    onDelete() {
      this.addressInfo={} 
    },
    onChangeDetail(val) {
      if (val) {
        this.searchResult = [
          {
            name: '黄龙万科中心',
            address: '杭州市西湖区',
          },
        ];
      } else {
        this.searchResult = [];
      }
    },
  },
};
</script>

<style lang="less" scoped>
@import url('../assets/css/addtheaddress.css');



</style>